import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Query,
  ClassSerializerInterceptor,
  UseInterceptors,
  UseGuards,
} from '@nestjs/common';
import { LessonsSortService } from './lessons-sort.service';
import { CreateLessonsSortDto } from './dto/create-lessons-sort.dto';
import { UpdateLessonsSortDto } from './dto/update-lessons-sort.dto';
import {
  GetLessonsSortDto,
  ReturnLessonsSortDtoList,
} from './dto/get-lessons-sort.dto';
import {
  ApiBody,
  ApiOperation,
  ApiQuery,
  ApiResponse,
  ApiTags,
} from '@nestjs/swagger';
import { JwtGuard } from '../guards/jwt.guards';
import { Transform } from 'class-transformer';

@Controller('lessons-sort')
@UseInterceptors(ClassSerializerInterceptor)
@UseGuards(JwtGuard) // 校验token是否通过
@ApiTags('排课模块')
export class LessonsSortController {
  constructor(private readonly lessonsSortService: LessonsSortService) {}

  @Post()
  @ApiOperation({ summary: '排课创建' })
  @ApiBody({ type: CreateLessonsSortDto, description: '' })
  @ApiResponse({
    status: 200,
    description: '成功返回200，失败返回400',
    type: CreateLessonsSortDto,
  })
  create(@Body() createLessonsSortDto: CreateLessonsSortDto) {
    return this.lessonsSortService.create(createLessonsSortDto);
  }

  @Get()
  @ApiOperation({ summary: '课程列表' })
  @ApiQuery({ type: GetLessonsSortDto, description: '参数可选' })
  @ApiResponse({
    status: 200,
    description: '成功返回200，失败返回400',
    type: ReturnLessonsSortDtoList,
  })
  findAll(@Query() query: GetLessonsSortDto) {
    return this.lessonsSortService.findAll(query);
  }

  @Get(':id')
  @ApiOperation({ summary: '排课详情' })
  @ApiQuery({ name: 'id', required: true, description: '排课id' })
  @ApiResponse({
    status: 200,
    description: '成功返回200，失败返回400',
    type: CreateLessonsSortDto,
  })
  findOne(@Param('id') id: number) {
    return this.lessonsSortService.findDetail(id);
  }

  @Patch(':id')
  @ApiOperation({ summary: '课程更新' })
  @ApiQuery({ name: 'id', required: true, description: '课程id' })
  @ApiBody({ type: UpdateLessonsSortDto, description: '' })
  @ApiResponse({
    status: 200,
    description: '成功返回200，失败返回400',
    type: CreateLessonsSortDto,
  })
  update(
    @Param('id') id: number,
    @Body() updateLessonsSortDto: UpdateLessonsSortDto,
  ) {
    return this.lessonsSortService.update(id, updateLessonsSortDto);
  }

  @Delete(':id')
  @ApiOperation({ summary: '课程删除' })
  @ApiQuery({ name: 'id', required: true, description: '课程id' })
  @ApiResponse({
    status: 200,
    description: '成功返回200，失败返回400',
    type: CreateLessonsSortDto,
  })
  remove(@Param('id') id: string) {
    return this.lessonsSortService.remove(+id);
  }
}
